<?php

namespace app\web\controller;

use app\web\service\OutletsService;
use app\web\service\VerifierService;

class OutletsController extends CommonController
{
    public function initialize()
    {
        $this->noCheckTokenAction = ["searchRes", 'getPriceCalendar', 'getInfo', 'getList', 'getAgreement'];
        parent::initialize();
    }

    // 网点列表
    public function getList(){
        if($this->returnData["code"] !== 0){
            return $this->return_result($this->returnData);
        }
        $service = $this->app->invokeClass(OutletsService::class, [$this->returnData, $this->params]);
        $this->returnData = $service->getList();
        return $this->return_result($this->returnData);
    }

    // 网点详情
    public function getInfo(){
        if($this->returnData["code"] !== 0){
            return $this->return_result($this->returnData);
        }
        $service = $this->app->invokeClass(OutletsService::class, [$this->returnData, $this->params]);
        $this->returnData = $service->getInfo();
        return $this->return_result($this->returnData);
    }

    // 最近搜索
    public function getSearchData(){
        if($this->returnData["code"] !== 0){
            return $this->return_result($this->returnData);
        }
        $service = $this->app->invokeClass(OutletsService::class, [$this->returnData, $this->params]);
        $this->returnData = $service->getSearchData();
        return $this->return_result($this->returnData);
    }

    //
    public function searchRes(){
        if($this->returnData["code"] !== 0){
            return $this->return_result($this->returnData);
        }
        $service = $this->app->invokeClass(OutletsService::class, [$this->returnData, $this->params]);
        $this->returnData = $service->searchOutlets();
        return $this->return_result($this->returnData);
    }

    //
    public function getPriceCalendar(){
        if($this->returnData["code"] !== 0){
            return $this->return_result($this->returnData);
        }
        $service = $this->app->invokeClass(OutletsService::class, [$this->returnData, $this->params]);
        $this->returnData = $service->getPriceCalendar();
        return $this->return_result($this->returnData);
    }

    // 获取协议内容
    public function getAgreement(){
        if($this->returnData["code"] !== 0){
            return $this->return_result($this->returnData);
        }
        $service = $this->app->invokeClass(OutletsService::class, [$this->returnData, $this->params]);
        $this->returnData = $service->getAgreement();
        return $this->return_result($this->returnData);
    }

    //
    public function prepareOrder(){
        if($this->returnData["code"] !== 0){
            return $this->return_result($this->returnData);
        }
        $service = $this->app->invokeClass(OutletsService::class, [$this->returnData, $this->params]);
        $this->returnData = $service->prepareOrder();
        return $this->return_result($this->returnData);
    }

    //
    public function submitOrder(){
        if($this->returnData["code"] !== 0){
            return $this->return_result($this->returnData);
        }
        $service = $this->app->invokeClass(OutletsService::class, [$this->returnData, $this->params]);
        $this->returnData = $service->submitOrder();
        return $this->return_result($this->returnData);
    }

    // 租车核销
    public function outletsVerification(){
        if($this->returnData["code"] !== 0){
            return $this->return_result($this->returnData);
        }
        $service = $this->app->invokeClass(VerifierService::class, [$this->returnData, $this->params]);
        $this->returnData = $service->handleOutlets();
        return $this->return_result($this->returnData);
    }
}